<template>
    <div>
        <button @click="num(sp,-1)">-</button>
        <span>{{sp.num}}</span>
        <button @click="num(sp,1)">+</button>
    </div>
</template>
<script>
export default {
    name:'numbtn',
    props:{
        sp:{},
    },
    methods:{
        num:function(sp,x){
            if(x==-1){
                if(sp.num<=0) return sp.num=0;
                else return sp.num--;
            }
            if(x==1){
                if(sp.num>=sp.stock) return sp.num=sp.stock;
                else return sp.num++;
            }
        },
    },
    
}
</script>
<style scoped>
span{
    width: 30px;
    display: inline-block;
}
</style>